<?php
/**
 * @copyright Copyright (c) 2021 勾股工作室
 * @license https://opensource.org/licenses/GPL-3.0
 * @link https://www.gougucms.com
 */

declare (strict_types=1);

namespace app\home\controller;

use app\base\BaseController;
use app\home\validate\FlowTypeCheck;
use app\home\validate\ExpenseCateCheck;
use app\home\validate\CostCateCheck;
use app\home\validate\IndustryCheck;
use app\home\validate\ServicesCheck;
use app\home\validate\WorkCateCheck;
use app\home\validate\InvoiceSubjectCheck;
use think\exception\ValidateException;
use think\facade\Db;
use think\facade\View;
use think\route\dispatch\Controller;

//Controller
class Rszs
{
    public function information_insured_personnel()
    {

        $param = get_params();
        $id = $param['id'] ?? '';

        $detail = Db::name('rszs_log_detail')->where('id', $id)->find();
        $insured_date = $this->get_month($detail['sybx_insured_yj_month']);
        $startDate = new \DateTime($insured_date[0]); // 开始日期
        $endDate = new \DateTime($insured_date[1]);   // 结束日期
        $interval = $startDate->diff($endDate);
        $detail['sybx_insured_yj_month'] =  ($interval->y * 12) + $interval->m + 1;

        $gsbx_insured_date = $this->get_month($detail['gsbx_insured_yj_month']);
        $gsbx_startDate = new \DateTime($gsbx_insured_date[0]); // 开始日期
        $gsbx_endDate = new \DateTime($gsbx_insured_date[1]);   // 结束日期
        $gsbx_interval = $gsbx_startDate->diff($gsbx_endDate);
        $detail['gsbx_insured_yj_month'] =  ($gsbx_interval->y * 12) + $gsbx_interval->m + 1;

        View::assign('detail', $detail);

        return view('index');
    }

    private function get_month($_date)
    {
        list($startDate, $endDate) = explode('-', $_date);
        return $this->get_new_date([$startDate,$endDate]) ;
    }

    private function get_new_date($_date)
    {
        $start1 =   substr($_date[0], 0, 4);
        $start2 = substr($_date[0], 4, 2);
        $end1 =   substr($_date[1], 0, 4);
        $end2 = substr($_date[1], 4, 2);
      return [$start1.'-'.$start2,$end1.'-'.$end2];
    }
}
